﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTcms.Common;

namespace DTcms.Web.admin.users
{
    public partial class user_edit_fast : Web.UI.ManagePage
    {
        protected string action = DTEnums.ActionEnum.Add.ToString(); //操作类型
        protected string _mobile = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = DTRequest.GetQueryString("action");
            this._mobile = DTRequest.GetQueryString("mobile");
            
            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this.action = DTEnums.ActionEnum.Edit.ToString();//修改类型
            }
            if (!Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(this._mobile))
                {
                    txtMobile.Text = this._mobile;
                }
            }
        }
       

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.users model = new Model.users();
            BLL.users bll = new BLL.users();

            model.group_id = 1;
            model.status = 0;
            //检测用户名是否重复
            if (bll.Exists(txtUserName.Text.Trim()))
            {
                return;
            }
            model.user_name = Utils.DropHTML(txtUserName.Text.Trim());
            //获得6位的salt加密字符串
            model.salt = Utils.GetCheckCode(6);
            //以随机生成的6位字符串做为密钥加密
            model.password = DESEncrypt.Encrypt(Utils.GetCheckCode(6), model.salt);
            model.avatar = Utils.DropHTML(txtAvatar.Text);
            model.sex = "保密";
            model.mobile = Utils.DropHTML(txtMobile.Text.Trim());
            model.reg_time = DateTime.Now;

            int result = bll.Add(model);

            if (result > 0)
            {
                Response.Redirect("/admin/company/company_edit.aspx?user_name=" + model.user_name + "&mobile=" + model.mobile + "&avatar=" + model.avatar + "&user_id=" + result.ToString());
                //JscriptMsg("添加会员成功！", "company/company_edit.aspx?user_name=" + model.user_name + "&mobile=" + model.mobile + "&avatar=" + model.avatar + "&user_id=" + result.ToString());
            }
            else
            {
                JscriptMsg("保存过程中发生错误！", "");
                return;
            }
             
        }
    }
}